//
//  ZZCListViewController.m
//  B段项目
//
//  Created by dllo on 15/12/25.
//  Copyright © 2015年 张智超. All rights reserved.
//

#import "ZZCListViewController.h"

@interface ZZCListViewController ()<UIWebViewDelegate>

@property(nonatomic,retain)UIWebView *webView;

@end

@implementation ZZCListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.view.backgroundColor = [UIColor whiteColor];
    
    self.titleLabel.text = @"详情";
    
    //图标
    UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(WIDTH - WIDTH/4.5, WIDTH/40, WIDTH/15, WIDTH/15)];
    img.image = [UIImage imageNamed:@"iconfont-pengyouquan.png"];
    img.center = CGPointMake(WIDTH - WIDTH/5, self.navigationController.navigationBar.frame.size.height /2);
    [self.rightView addSubview:img];
    
    
    self.webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    self.webView.delegate = self;
    self.webView.scrollView.bounces = NO;
    [self.view addSubview:self.webView];
    
    
    MBProgressHUD *hub = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [hub show:YES];
    hub.labelText = @"正在为您加载.....";
    [self.view addSubview:hub];
    
    
    NSString *urlStr = @"http://api2.pianke.me/timeline/info";
    NSString *bodyStr = [NSString stringWithFormat:@"auth=&client=1&contentid=%@&deviceid=0F79DA7D-8DF2-416D-B3C3-7BD488A50BDD&version=3.0.6", self.contentId];
    [ZYTools postUrl:urlStr body:bodyStr result:ZYJSON requestStyle:ZYRequestString headerFile:nil success:^(id result) {
        NSMutableDictionary *dic = [result objectForKey:@"data"];
        [self.webView loadHTMLString:[dic objectForKey:@"html"] baseURL:nil];
        
        [hub hide:YES];
    } failure:^(NSError *error) {
        
        [hub hide:YES];
    }];
    
    
}



#pragma mark --  webView自适应
- (void)webViewDidFinishLoad:(UIWebView *)webView { //webview 自适应
    
    
    NSString *str1 = [NSString stringWithFormat:@"%0.2f",WIDTH - 20];
    
    [webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:
                                                     @"var script = document.createElement('script');"
                                                     "script.type = 'text/javascript';"
                                                     "script.text = \"function ResizeImages() { "
                                                     "var myimg,oldwidth;"
                                                     "var maxwidth= %@;"//缩放系数,调动这个参数可以改变图片的宽度
                                                     "for(i=0;i <document.images.length;i++){"
                                                     "myimg = document.images[i];"
                                                     "oldwidth = myimg.width;"
                                                     "if (oldwidth >= 300) {"
                                                     "myimg.width = maxwidth;"
                                                     "myimg.height = myimg.height;"
                                                     "}"
                                                     "}"
                                                     "}\";"
                                                     "document.getElementsByTagName('head')[0].appendChild(script);",str1]];
    
    [webView stringByEvaluatingJavaScriptFromString:@"ResizeImages();"];
    
    NSString *str = @"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '100%'";
    [webView stringByEvaluatingJavaScriptFromString:str];
    
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
